package com.hskn.hss.module.tloilcostcfg.vo;

import com.hskn.hss.core.annotation.Excel;
import com.hskn.hss.module.depart.entity.SysDepart;
import com.hskn.hss.module.tlcar.entity.TlCar;
import com.hskn.hss.module.tlcartype.entity.TlCarType;
import com.hskn.hss.module.tloilcostcfg.entity.TlOilcostCfg;
import com.hskn.hss.module.user.entity.User;
import com.hskn.hss.utils.Tools;
import lombok.Data;
import org.apache.commons.lang3.math.NumberUtils;
import org.apache.poi.ss.usermodel.IndexedColors;

import java.io.Serializable;
import java.math.BigDecimal;
import java.text.NumberFormat;
import java.util.Date;
import java.util.Objects;

/**
 * <p>
 *
 * </p>
 *
 * @author hskn
 * @since 2021-05-05
 */
@Data
public class TlOilcostCfgExecelVO implements Serializable {
    /**
     * 车辆id
     */
    private String carnumid;
    /**
     * 车牌号
     */
    @Excel(name = "车牌号（必填）", align = Excel.Align.CENTER, height = 18, width = 16)
    private String carCardNum;
    /**
     * 车辆类型
     */
    @Excel(name = "车辆类型", align = Excel.Align.CENTER, height = 18, width = 16)
    private String carTypeName;
    /**
     * 驾驶员
     */
    @Excel(name = "驾驶员", align = Excel.Align.CENTER, height = 18, width = 16)
    private String driverName;
    /**
     * 创建部门id
     */
    private String deptid;
    /**
     * 机构名称
     */
    @Excel(name = "所属机构", align = Excel.Align.CENTER, height = 18, width = 24)
    private String deptName;
    /**
     * 油卡编号
     */
    @Excel(name = "油卡编号", align = Excel.Align.CENTER, height = 18, width = 20)
    private String oilcardnum;
    /**
     * 总费用(元)
     */
    @Excel(name = "总费用（必填）", align = Excel.Align.CENTER, height = 18, width = 18, color = IndexedColors.GREEN, cellType = Excel.ColumnType.NUMERIC)
    private BigDecimal totalcost;
    /**
     * 加油时间
     */

    private Date costtime;
    /**
     * 加油时间
     */
    @Excel(name = "加油时间（必填）", align = Excel.Align.CENTER, height = 18, width = 18)
    private String costtimeString;
    /**
     * 加油量(L)
     */
    @Excel(name = "加油量", align = Excel.Align.CENTER, height = 18, width = 18, color = IndexedColors.GREEN, cellType = Excel.ColumnType.NUMERIC)
    private BigDecimal oilnum;
    /**
     * 燃油类型
     */
    @Excel(name = "燃油类型", align = Excel.Align.CENTER, height = 18, width = 16)
    private String repairreason;
    /**
     * 单价
     */
    @Excel(name = "单价（L/元）", align = Excel.Align.CENTER, height = 18, width = 18, color = IndexedColors.GREEN, cellType = Excel.ColumnType.NUMERIC)
    private BigDecimal oilunitprice;
    /**
     * 码表里程(km)
     */
    @Excel(name = "码表里程(km)", align = Excel.Align.CENTER, height = 18, width = 18, color = IndexedColors.DARK_YELLOW, cellType = Excel.ColumnType.NUMERIC)
    private BigDecimal clockmileage;
    /**
     * 地址
     */
    @Excel(name = "地址", align = Excel.Align.CENTER, height = 18, width = 36)
    private String address;
    /**
     * 缴费人
     */
    @Excel(name = "缴费人", align = Excel.Align.CENTER, height = 18, width = 18)
    private String payusername;
    /**
     * 备注
     */
    @Excel(name = "备注", align = Excel.Align.CENTER, height = 18, width = 40)
    private String remark;

    public TlOilcostCfgExecelVO() {
    }

    public TlOilcostCfgExecelVO(String carnumid, String carCardNum, String carTypeName, String driverName, String deptid, String deptName, String oilcardnum, BigDecimal totalcost, Date costtime, String costtimeString, BigDecimal oilnum, String repairreason, BigDecimal oilunitprice, BigDecimal clockmileage, String address, String payusername,String remark
    ) {
        this.carnumid = carnumid;
        this.carCardNum = carCardNum;
        this.carTypeName = carTypeName;
        this.driverName = driverName;
        this.deptid = deptid;
        this.deptName = deptName;
        this.oilcardnum = oilcardnum;
        this.totalcost = totalcost;
        this.costtime = costtime;
        this.costtimeString = costtimeString;
        this.oilnum = oilnum;
        this.repairreason = repairreason;
        this.oilunitprice = oilunitprice;
        this.clockmileage = clockmileage;
        this.address = address;
        this.payusername = payusername;
        this.remark = remark;
    }

    public static TlOilcostCfgExecelVO buildTlOilcostCfgExecelVO(TlOilcostCfg oilcostCfg, TlCar car, TlCarType carType, User user, SysDepart depart) {
        /**
         * 车辆id
         */
        String carnumid = oilcostCfg.getCarnumid();
        /**
         * 车牌号
         */
        String carCardNum = car.getCarnumber();
        /**
         * 车辆类型
         */
        String carTypeName = carType.getTypename();
        /**
         * 驾驶员
         */
        String driverName = user.getName();
        /**
         * 创建部门id
         */
        String deptid = oilcostCfg.getDeptid();
        /**
         * 机构名称
         */
        String deptName = depart.getDepartName();
        /**
         * 油卡编号
         */
        String oilcardnum = oilcostCfg.getOilcardnum();
        /**
         * 总费用(元)
         */
        BigDecimal totalcost = Objects.nonNull(oilcostCfg.getTotalcost())?oilcostCfg.getTotalcost().setScale(2,BigDecimal.ROUND_HALF_UP):BigDecimal.ZERO;
        /**
         * 加油时间
         */

        Date costtime = oilcostCfg.getCosttime();
        /**
         * 加油时间
         */
        String costtimeString = Tools.getYearMonthDayString(oilcostCfg.getCosttime());
        /**
         * 加油量(L)
         */
        BigDecimal oilnum =  Objects.nonNull(oilcostCfg.getOilnum())?new BigDecimal(oilcostCfg.getOilnum()).setScale(2,BigDecimal.ROUND_HALF_UP):BigDecimal.ZERO;
        /**
         * 燃油类型
         */
        String repairreason = oilcostCfg.getRepairreason();
        /**
         * 单价
         */
        BigDecimal oilunitprice = Objects.nonNull(oilcostCfg.getOilunitprice())?oilcostCfg.getOilunitprice().setScale(2,BigDecimal.ROUND_HALF_UP):BigDecimal.ZERO;
        /**
         * 码表里程(km)
         */
        BigDecimal clockmileage = Objects.nonNull(oilcostCfg.getClockmileage())?new BigDecimal(oilcostCfg.getClockmileage()).setScale(2,BigDecimal.ROUND_HALF_UP):BigDecimal.ZERO;
        /**
         * 地址
         */
        String address = oilcostCfg.getPlace();
        /**
         * 缴费人
         */
        String payusername = user.getName();
        /**
         * 备注
         */
        String remark = oilcostCfg.getRemark();

        return new TlOilcostCfgExecelVO(carnumid, carCardNum, carTypeName, driverName, deptid, deptName, oilcardnum, totalcost, costtime, costtimeString, oilnum, repairreason, oilunitprice, clockmileage, address, payusername ,remark);
    }
}
